/**
 * @Author @fiber-cloud
 * @Date 2025/8/31 13:24
 */
public class ThreadDemo6 {
    public static void main(String[] args) {
        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread t1 = new Thread(() -> {
            synchronized (locker1){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                synchronized (locker2){
                    System.out.println("线程1把两个锁都拿到了");
                }
            }
        });


        Thread t2 = new Thread(() -> {
            synchronized (locker1){

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e ) {
                    e.printStackTrace();
                }

                synchronized (locker2){
                    System.out.println("线程2把两个锁都拿到了");
                }
            }

        });

        t1.start();
        t2.start();
    }
}
